Addedt first unittest and fixed some bugs