guarded code against division by zero (original suggestion by Mateusz)