Added logging and fixed a bug associated with empty queries.