Refactor filter, move type filter into own func