Refactored check for primary and fixed typo.