refactored api, improved text query handling