refactored 12 solution