wrote javadoc. fixed some bugs