move functionality
refactored for reuse and readability