fix a lot of problems discorvered by findbugs