Refactored code, edited prompts for clarity.