modified to trap error reporting