on refactoring and fixing thread bug