'count -d' refactor & add sort