fixed calculation of theta