Fix some bugs and change the directory structure of generated files