refactor client js to not pollute global namespace