fixed problems with  program hangs