refactor functions