Fixed logging at end of script