Revert some changes and fix some bugs.