added custom field support, better file appending