Added more tests and refactors