refactored mathyruby soln