refactored urlencode so things are packed and unpacked