Fix test failures and a small rewrite of celery_instance.