* refactor event replacements
* truncate file before write