Improve performance of summary function.