Add functional tests; more sane error reporting