improved problem 5