Event listener ordering + bugfixes, cleanup and various improvements