Simplified counting of GCDs
Simplified pattern distance calculation
Reordered functions, documentation