add unit test and refactor all classes