Refactor before-hooks