updated to check for type of layer