Simplifying the threading code
Cleaning up import order