Supports smart redirection upon login/register/logout + refactoring.