improved handling and passing of layer variable