Fix bug in finding modules and populating FKs