Only write out modified persistence windows

This contains only the changes, and should apply cleanly onto master.