A number of findbug fixes

findbugs found several issues which could result in bugs and/or difficult time in debugging some issues.