added keygen function