added query prompt and refactored code