Some changes to thread-management and initialization