better error handling; logging