Added protection for accidental shell closing