Added removeByMask method.

Also, fixed a bunch of bugs.