improved generating reports from database