First correct solution to problem 3