improved logging, better error handling