Code clean up and handling FIFO errors