wrote refactored solution