Refactored calendar code