improved error handling & logging