Move functions from test to main.