added encodeURIComponent() where necessary