factor out error (non-)handling