Server detection made more robust