Refactor valid_uri into is_valid_uri