Reworked client code and JS API