move functions into common and test