Prevented modulus by zero

Also updated the error message to "Result is undefined."