add save_keypairs function, fix save keypairs mechanism