Refactor threads a bit with common file