refactored code; moar d-r-y