huge thread refactor