Escape query strings
Handle empty queries better