improved solution to p17