modified and fixed some bugs