Small improvements in error handling