Fix case referenceMissing and refactor