Major rewrite of npx code (npx-0.5 + 2 patches to it)