Changes from previous version: * The actual change to filtering separated from other changes that I think have more chance at being accepted. * Changes to integral function split into mulitple commits * Whitespace fixes * Good/best patch has fix for bug noticed by Søren