Added some slightly more complex table handling so that more logic can happen.