refactoring some functions