refactored challenge problem 12 to be more concise and readable