add header and cleanup logging