Take out to_query and to_uri helpers
Refactor error reporting