Fix bug with null reference