Replacing busy loops with sleep mode