Fix null checks, simplify ternary expressions