Merge "Improve heuristics for orientation detection."