Add some javadoc, convert keySet loops to entrySet loops