Make sure to check that a summary exists before using it

Failing to check for this caused errors when write_summary was set to false.