More efficient event handling, with hashmaps