Added check for foreign keys