Added additional logic to control fifo