fixed bugs in finding correct target direction