Add sanity check for ref in eventSelected

Thanks Dima73