This is very generic helper method. As it may be useful in many places, we should consider extracting it to some shared utility lib