Optimize Algorithm