fixed small bug with fifo.  Tested it with known outputs, seems to be correct.