improved error handling end logging