Various timeout fixed

I saw sometimes problems in sleep function, please review