Improved solution to 002.