Some code flow fixes catching errors