Convert to top level function