imrpove laggy undo function