Add header guards
Extract logic for read-write filters