Cleaned up masks and implemented toString() for masks.
Cleaned up patterns and added toString() for patterns.