move constant folding code to the correct location; some small fixes