Better error-checking, issue #4