Refactor the constant folding code into it's own function. And call it from both