Improved dealing with exceptions + logging