functions refactor