Improved log handling