fixed some bugs and enhanced tests