Rewire slightly and fix some bugs