Cleanup and add javadoc