Renamed internal functions to ns_* to avoid naming conflicts on amalgamation