more explicit error catching

also fixed some unused imports along the way