Fix out of scope bug