Fix possible null reference exception