refactor code so events are saved in new format