improve generate masks