Added checking for null in listener