fix some bugs (still buggy)