refactored to be DRYer