Add sorting and total sum