Refactor code : Extract columns from table while filtering