Added instancing handling and visible flag
refactored script structure