Codestyle fixes and refactoring