Inlined C code makes this super fast. Address boundary error on larger datasets.