Modified gendoc.sh for portability and adaptability