Fixed changedirection function.