Added second detection. Writing the code based on the mask next