I have tested the code and it works.  Do you know under what circumstances the call to `getMainTable` will fail?