refactored code in main.rb