improved algorithm performance