Make UT code compilable and fix some UT failures