made some small changes for allowing for larger numbers of iterations and different output types