improved problem 4