Extract a main() function.