Refactored duplication of code in main.rb