much error handling, clean exit code, and code organization