implement masks and raise some useful errors