Thanks, this was very helpful. I've refactored this to pass the view as a parameter instead.