add unit tests and many fixes
fix merge