Tried to fix some bugs