Refactored Java code to much more OOP style.