Fix for PR #915, keep track of the qtables length

Keep track of the qtables length, Don't try to calculate it in a way that doesn't work with dynamically allocated arrays.