Calendar code refactoring