Adding logic to add and remove hooks