Code cleanup
Put main() in a separate file (as for the other tools)