Improve method that detects when it is done so that it never gets stuck
waiting forever