Re-factored code to correct defects in calendar logic.