WOW! I am trying to do pretty much the same thing. Amazing job! You are so much better at the coding than me.
Lately I've been experimenting with different types of IR communication, both transmitting and receiving, & it seems like I always strart with drawing a state machine on paper, coding it in a big switch statement in a timer interrupt routine, & the code just grows. Like "a journey of a thousand lines of code starts with state = IDLE."