Added proper encoding of segment, query, fragment, and user-info.
Replaced 'joinString' with a better implementation.