Logging and code cleanup