Tests: fixed the remaining broken tests and potential crashes