refactor thread sleep