Fix null ref exception