implemented functions to deal with keys and prepare protocol