moved router before hooks to one function