refactored 36 solution