Switch function to avoid undefined