Finalized implementation, added unit tests and javadoc.