Code refactor and added javadoc comment to functions and classes.