Refactoring the function to check for private and
public keys