refactor some functions.