refactored problem 006