improved solution to 002