unit testing, fixed some bugs