Large refactoring. Tables with foreign keys.