refactor helper functions