Fix unit tests and some FindBugs warnings