replace beforeThan and afterThan by before and after