Slight improvement on error handling