error handling: return proper exit code if fails