Matches the C++ version

Uses the new design from the C++ version, which is a lot faster for certain data arrangements and no slower overall