refactored my solution