refactored error raising and passing