refactor nimsapiutil