Fix invalid logic and proper traceback display