Refactoring and Problem 3 solved.