Make dynamic filter and sort re-usable

I have compiled it but not run. Please try if it works.