Fixed a bug in calculating angles.