Cont. unit testing, fixed some bugs found