If would be better to test if vector is undefined before calling removeLayer.