Added increased error checking and handling of fields with multiple values