fixed some bugs yet not complete