Cleaned up the code and the javadoc