Cleaned the code and updated with javadoc.