Static analysis

Fixes some problems discovered by findbugs, metrics projects.