use a StringBuilder or similar object to construct the output string, rather than concatenating strings using the += operator. also add more error handling, such as checking for missing fields in the input data, to make the code even more robust.