Final improvements added for problem 6