Revised code for solution to Challenge 127 [Intermediate]