moved code to top level