refactored solution to 18