Moved the filtering to the database