change file structure and fix bugs