Critical null ref exception fixes