Fix some errors on js, changed socket handling for rpc client and hopefully fixed high cpu usage #27