Tweaked event handling to make searching work as expected