Fix element.before/after NPEs