Refactored threads into a separate file