make a one-pass implementation