cleaned up code, added some javadoc style comments