Improved loging code