Logging and exception cleanup