A few more simple/trivial optimizations

Move the filter processing to the very beginning, so that the pools are
created on top of the filtered list. With this change, the algorithm behaves
as expected when filter-only is applied and we don't need the check for
duplicates at the end, so remove it.

Also includes a couple of very minor, cosmetic refactorings.