Some fixes to make dynamic reports work.

Still many issues left.