Fix null exception bug