working except for total sum