reordered code, and added creation of the field names