Cluster head recovery algorithm for wireless sensor networks