more rigorous sanitization of some inputs
guard against divide by zero