Fixed unused imports, variables and some bugs found by FindBugs.