calculating summary before opening output handle