Reworked the io.c routines from a loop using continue to a state machine
using function pointer and switch statement.