fixing the pixel mask code after some testing