DRY'd up ex04.rb code