More refactoring, renamed events and functions, removed unused functions and events.