code cleanup and optimizations
AI trigger in bottom-right corner