optimize problem 4