More onto refactoring
Refactored some types, added constant folding.