Fix calculate patterns, closes #520