Fixing issue #189 from Simon Sokolov
Aligned with pull request #390, for better performances
Merge pull request #418 from LocutusOfBorg/189-fix2

Fixing issue #189 from Simon Sokolov
Merge remote-tracking branch 'upstream/master' into fix-sleep