Moved some funcs into NGfuncs and RWMS_sql