Added record plots code and moved diagnostic / result output inside loop