fixed the first part of k-shingles.

also the software engineer in me refactored the code out to be more
readable and DRY.