Updated anagle calculation code