Added nanosleep call to prevent CPU hogging (backported from unstable/v0.4).