fix various bugs for tests