Refactoring: removed Expression class.
Implemented the calculation of temporary storage.
Implemented cache for cost and dimension calculations and for string building.