Implemented the hook function