logging, better error handling