Improved solution to easy 171