first pass algo