turn main test part into function