Added unit tests and some fixes, javadocs