added no tail recursive collect