changed direction logic