implementing thread manager class; migrating it into the project, plus refactoring