Fixed bug in before/after logic.