refactor: split up the client code, use commonjs

Closes #253