Created function to perform primay key check. Refactored.