Code cleanup and logging