Added try/except blocks around main functions