Fixed major error in end condition.