beforeBlock and afterBlock should be checked against nil