rewritten to handle new foreign/unique/primary syntax