Added loop over indices

Closes #3