Added more test and made some code more testable