Better checking for end value