Fixed some bugs dicovered by FindBugs