Refactored + Javadoc added.