Fix an issue in element writing