Replace sleep with wait/notify