Fix calculate patterns.
Merge pull request #522 from Mignari/master

Fix calculate patterns, closes #520