Fix small problems at generate key and sanitize