Cleaned up code, improved some javadoc.