little refactor: take out testfn from test function, and declared it in global