Refactored to reuse #primary_key? method

The #primary_key? method has already been written to check the type is primary key or not. Modified the method li'l bit to reuse in other places.