validate foreign key
remove unused entities