Improve handling of functions that ref tables