Removed some debug code and added javadoc and comments