added beforeHandler method