refactoring pulling up duplicated functions