Looks like a function used in multiple places. Move out to a util class?