I ma sure this code is done somewhere can you reuse it? if not feel free to add it in one of the common utility classes