refactoring and hooks