Added signing and verification. Factored out repititive code.