imported the latest working version from production; added in handleError, Before Hook and After Hook.