Adds undo functionality. Not tested yet.