Fix some more notices.
Optimize loading of child tables by moving unneccessary stuff out of the loop.