Ported over the state machine and PSSC 3 & 4 code