refactoring formatEvent