main.c: better error handling