added crash protection code