fixing broken foreign key bugs