Fixed several Checkstyle issues
- refactored methods to lower the cyclomatic complexity.
- added Javadocs.
- reordered fields according to their visibility.
- created fields for constant values that were used more than once.
- other small changes.