Added check for the mask's existence before using it