General comment on testing: given that there are in some sense two code-generators with different indexing logic (n_elements = 0, n_elements > 0) there should be tests that ensure both of those generators produce correct code for the cases they handle.