Refactor home page filtering in pages_controller