Move mask forming code to resource manager