refactor codes in scheduler.rb