foreign_keys updated, refactoring