refactor some functions