Sleeping works

Fixes #707 and FS392. Cherry pick because 1e87f2f / 8d2ebf8e19e1556d256f75678d2272bb6739030f was accidentally pushed to master?