Refactor and javadoc