refactored math expression internals