improve base_url detection