algorithm first pass