Fix bug with numerical issues