adds more events and refactors the code