fixed mistakes in trimming /ht Sebastian Kopf
minor tweaks from having run through everything with a small example data set