It almost seems like this should belong to a separate Utils class or something.