Changed to redmask function; added some etc. utilties