fixed error and uses masks