Fix null-pointer exceptions