refactored out helper functions