Refactor summary code and small fixes