It seems like you have this function declared in several places. I think you should put it somewhere reusable.