Simplify sort and count length