more fixing of foreign keys and ordering