Tidy up JS Client

API is the same and no functional changes other
to tidy up backend to streamline implementation.