Optimize and fix linux sleep bug