added refactored solution and driver test corrected to pass rspec