refactored into it's own function