improve sensor direction algorithm