bug fix

fixed local variables being defined as global. improved trigonometric
algorithms.