Add some NPE checks and change event priority