change to onBeforeAction hook