reformatting mostly to tidy code. loop in run method.