fix unit tests and refactor