refactor fn