REfactored problem 3