fix the background thread, code refactoring