refactored functionality