refactoring of some functions