Added unit tests and fixed failures