Added the vec implementation from clibs
Use reallocarray instead of realloc