Fix error issue and improve UT