Use explicit orientation detection

Since it can be 0, we should check against undefined instead
Removed unused code