attempt to fix param problem, with multiple unnecessary writes. the rewrite code has been changed so that it will not rewrite the same parameter multiple times.
added some cleaned uses of "const".

fixed parameter saving!