Fix NilClass exception bug.