replaced 'IF EXISTS' logic with a try/except