refactor of functions