Added some error handling to hooks.js