now we can put rewrites inside and they are moved to the top

+ some bug fixes