Fixing a bug causing application to hang