Added division by zero protection.
Added support for negative numbers.