Moved autocontext into its own function.