CLN: Move masks into a separate file. Reduces duplication, makes things easier.
API: Expose max_iterations to batch and locate.
API: Expose locate logic to locate/batch through filter_before, filter_after.