merged copy from ngclient