fixed some bugs for single element and if last element subtraction isn't zero