Some quick tidying and commenting to make loops more readable.