NSM: Refactor nsm_handle creation into a helper function