many cleanups, ported which.first