added undo, fixed js nesting