added null reference check to prevent ga reported crash bugs.