Guard against divide by zero, and add tests to check that sort of thing