changed logic in algorithm to allow for zero valued coefficients