changed new rex_sql() to factory