Refactor hooks.rb