add error handling in MAIN rather than just stop