Fix null pointer exception bug