implemented leader election with threads