Fixed bugs in counting substrings

Now it finds the right amount of substrings. Also substrings that
aren’t long enough are padded with 0’s.