Monster refactoring of everything in client.js to its own folder.