Add beforeLoop and afterLoop callbacks