Refactored, added unit tests, added javadoc, fixed bugs