Corrected some bugs