Added debug module
Added try/except and minor tweaks