Fixed the use of nanosleep which removed a spinloop and degraded the performance dramatically.