general bugs fixes and cleaning

Bug fix: [yes]
Feature addition: [no]
Backwards compatibility break: [yes]
Unit test passes: [yes]
Checkstyle issues: [no]
ChangeLog updated: [no]