Twiddled with a few things (i.e. 3rd nested loop conditions for AMO
clauses)