Some fixes
Add unit tests