Resolve "Prevent code duplication in python codegen"
Closes #103 (closed)
Managed to reduce about 200 lines by not have duplicated templates. Since the total git diff is no so easily understandable I did two commits, the first only removes the old functions and the second adds the new. So you can see commit by commit and the total diff, which ever way you like.