One thing you lose by moving this in a function is that you will call this method several times, and it's actually an expensive call (it does a search). Would be better to cache the answer somehow, I guess.