implemented most of the pattern stuff