checking for valid middleware