Fixed test failures and crashes