Change spin loop to a sleep loop.