Fixing Exceptions and logging