inproved problem 5 performance