Changed logic and added file dialog for missing references