refactor client code to be simliar to Javascript API