Added more unit tests and fixed minor bugs