reformat
refactor filtering function