Added missing error check; expanded tests.