Refactored problem 008