added max iterations, fixed bug in theta epsilon check