This loop is mostly duplicated from `list_bucket` above.  Can we factor it out?