Rework sleeping function
sleeps get interrupted by IO so sleeps are often not long enough. This
makes some funtions like setchcurve a bit flunky because of
race-conditions.
Workaround is to retry sleeps until they are done.
Needs a better fix!