Using timeout instead of sleep