Added explicit division by zero checks. Added tests for them