tidied up code
added iterations stop