Event listener refactoring and various cleanup