Improved FIFO logic