Exception logging and code cleanup.