Getting rid of a potencial floating-point exception by adding some extra checking...