Fixed InternalError exception for incorrectly nested tables and added some debug functionality