write_entry(): cleanup of some duplicated code