fixed gen_id()