functions works called interactively but not in a hook