fix direction function