adjusting gen_rst script and make it more general