Refactory code to check null listener situation