remove some code redundancy
tweak order of constant generation a bit