Fixing bug in write_element_values() where wrong number of vars was computed.