AI Refactor Addresses Bugs #1 and #2