OK, that makes some sense.  What is the input `mask`?  Is it like the example below (line 107)?  That one seems like it should be the *output* of `scan`.