Fixing undefined errors found and managing layerOptionsCollection correctly.