using external function to detect direction