Optimize the LCD state machine