Improve exception logging and global vars
Fix typo