add error handling and improve logging performance with big piece of data