changed fk to ext_id; use AR.table_name to retrieve table names rather than inferring independingly from class name; some refactoring; added some tests