I have not spent any time optimising the generated programs but they do not look totally unreasonable from a cursory inspection. Fixes #158