Fix Optimize Query