Refactored the two largest chunks in calendar.rb