cleaned up code, added javadoc