Cherry-picked commits 3d9380f and 308964e from no-compass branch