Simplfied the key stuff a bit