PLAT-5223 Improved builder to handle empty arrays and be generally more efficient.