Rebase due to recent conflicts with only a trivial whitespace fix, otherwisethe same as the previous version.
--Daniel Gustafsson