Improve summarize command, fix various bugs.