Replaced sleep with select.