add foreign key ++ fix some bugs