Revert needless changes and fix some bugs