replaced fromString loop with encodeURIComponent hack