ajd updated to cpp style loops