I think this function should be in utils.