move function to top level