Filters & AST fixes

Mergable version of #3642 with some additional fixes. Please test with compilation server!