move queueForLayer function block into template block