Added check for end situations