Some minor errors with Ref.bgThread, but it runs.