Changed escape to encodeURI and added decodeURI where needed