added outer angle loop and inner rate loop