"made some changes to the code where I vectorize the raster output from clump which is a faster data type to compute over compared to the rasterLayer objects"
merged the branches and fixed a hardwired "shp" variable line