Added JavaDoc, Fixed some bugs, added tests