reduced number of iterations and removed commented out code