Factor out exit code
Factor out signal handler into utils
Fix compile errors