Add safety check on GetLeader.
Reorder some code to remove warnings on 1.7 compiler.