fixed algorithm to have negatives