Rewrite of clipping and masking. Now used similarly to 'grid.clip'.

Also bugfix to 'grid.clip'. It was unwinding the tree too early.