improve code for producing summaries