Cleanup, Refactoring, Minor fixes

Please take a look at the three commit messages for details.