VERY MESSY but sort of functional RTC code