fixed some bugs in new implementation