fix the code index ref to scratch