refactored to separate helpers from logic