proper number of iterations and more fixes