changed mask algorithm (again)