Added try/except and minor tweaks