BF: Make error handling more robust