Pull request for Issue665

@dretrex 
@davidChevrier 
I'm not sure how big tables.count() typically is, but if it's a lot, a simple optimization would be to make the for loop look like:

```
for (int iSampleTable = 0, iSampleTableSize = tables.count(); iSampleTable < iSampleTableSize; iSampleTable++)
```