Changing encoding to encodeURIComponent and more comments

Changing encoding to encodeURIComponent from encodeURI as that is the
correct function. Adding some comments to better describe the different
settings and more debug messages.