Hello,
Just disable Optimization in functions definition. Select the function definitions, right click Optimization|None or Numeric. Just hover the mouse over the regions before and after to see the difference.
Here is the picture:

This is not possible in Live version from this site.
Btw, there were few reported problems with Symbolic optimization. I do not have the slightest idea what is the catch (in this case maybe the problem with trigonometric functions and multiple results combining with the reorganizing of expression) but the workaround about some suspicious results is to disable the Optimization of the problematic regions.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"