Refactored Problem 1