fixed logic, except for sum