Fix or work around scope/thread problems