better bearing algorithm