fixed bug in saving patterns to file