Fix some assorted bugs with filtering and deps

Details in the commits.