use instanceof instead of isVar() and friends; also better undo