updated direction logic