New way to limit sample rate, not tested yet.
Fixed multithreading.