improve error-checking