Added checks for numerical issues