As the JS str.replace(' '/g, '\\20); makes the script hangs I've added second escape for JID with 2 spaces.
TODO: Make more elegant way of doing things.