refactor some code