Fixes test suite + adds some defensiveness