refactor the main app and events