Fixed Undo bug(FIFO), code cleanup