fixes #5
rewrote the pattern-matching
fixes #7