Cleanup and refactoring. Codestyle fixes. step 2