fixed optimized code