ENH: simplified the way of finding the Q indices by using a mask