Fixing bug and adding try/except handling with cleanup. Yay!