Unit test added, gen_key bug fixed, new exceptions added