separated function from the hook