Fixed refactoring and added Javadocs.