Added unit tests and other small changes