Fixed an error in handling multi-line template bodies. Added a small text cleaning routine.