Copy pubkey improvement

Fixed the port issues and added validation to the pubkey copying