rough hacks to fix local ref issues when threaded in 4.0+