This function could be more efficient.