fix python generator
remove a few redundancies
Javascript port