more sophiticated error check

* two examples, now consolidate common operations