fixed the divide by zero errors with gradient().