Error handling improvement, add some additional logging