Added conditional sleeping