Refactored after applying new type checking last week and added comments/javadoc everywhere. Fixed some quality violations according to sonar.