Refactor bot filtering code.