Tweaked code from assignment_4.rb #4