avoid undefined inside if