finished refactoring, need to comment the code