issue #1098: added better error checking
issue #1098: some tests for error checking