added beforeQuery and afterQuery callback