reliable code

Eliminated freezing and crashing