Implement query by substring. Code cleanups.