refactor to remove similar functions