#487 Updated again the middelware logic for checking TOS to work properly