Compressed the threads_dict code into one shared function
Removed unused imports
Changed elifs to ifs
Changed elif clauses to if clauses