Fix temp counter

The code to increment the temp counter was in the outer loop, which had only two elements, rather than the inner loop, so it wasn't working.  This pull request fixes that.