Change main() to have only one exit code flow, used also on errors