pkey_size should be private
inline a single use function
move some shared logic to functions