fixed some bugs for the code