add tests and refactor tests