added conditional with error reporting