functions refactored