Refactor client main.js