Cleaned up more code and wrote javadoc comments