rework cs filtering using a more functional approach