Merge pull request #240 from alex/cleanup

Simplify the code by doing the filtering earlier, rather than later