fixed error in how the mask was being calculated