improve algorithm performance