Fixed pattern matching to match patterns at any orientation, added tests