More efficient calendar generation code