Improving algorithm performance