Fixed some bugs found by FindBugs