Added guards around bad calculations.