refactore some code