Fixed some bugs
Revert "Fixed some bugs"

This reverts commit 50c1603121703aa176cb22ab08230f11d6bc4b2d.
Revert "Revert "Fixed some bugs""

This reverts commit fdc0794326f22012eed7bc305b93af1afd1560ee.