add writeElements and writeStats