Fix callback functionality so undo works as expected