Refactoring and javadoc added