Refactored to validate private and public key