More variable cleanup
Updated header write to ensure consistency of fields
fixed test