Fixed several Checkstyle issues
- refactored methods and split them up into smaller parts.
- removed unnecessary code and other small changes.