Modified to adhere to PSR-2 and only call parse_url once