Refactored URL parsing and generation.