add query prompting and fix bugs