rearrange code by modules & add tests for filtering