Implement gathered loops.

Closes #122.