Adding more unit tests and fixes