Add explicit error handling in more places