added mask checking